import { createRouter, createWebHashHistory } from "vue-router";
import routes from "../router/routes"
import NProgress from "nprogress";
import "nprogress/nprogress.css";

const router = createRouter({
  history: createWebHashHistory(),
  routes: routes
});

router.beforeEach((to) => {
  NProgress.start();
  const { adminname } = JSON.parse(localStorage.getItem("user"))?.uesrdata || ""
  if (to.path != "/login" && !adminname) {
    return {
      path: "/login",
      query: {
        redirect: to.fullPath,
      },
    }
  }
})

router.afterEach((to) => {
  NProgress.done();
  document.title = to.meta.title
});

export default router;
